package edu.buaa.energy.transaction;

import com.alibaba.fastjson.annotation.JSONType;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;
import edu.buaa.common.transaction.AbstractTransaction;

import java.util.List;
import java.util.Map;

public class ImportTemporalDataTx extends AbstractTransaction {
    public List<EnergyStatus> data;

    public ImportTemporalDataTx() {
        this.setTxType(TxType.tx_import_temporal_data);
    }
    // default constructor and getter setter are needed by json encode/decode.

    public ImportTemporalDataTx(List<EnergyStatus> lines) {
        this.setTxType(TxType.tx_import_temporal_data);
        this.data = lines;
        Metrics m = new Metrics();
        m.setReqSize(lines.size());
        this.setMetrics(m);
    }

    public List<EnergyStatus> getData() {
        return data;
    }

    public void setData(List<EnergyStatus> data) {
        this.data = data;
    }

    public static class MultiEntityEnergyStatus {
        private int timePoint;
        private Map<Integer, Float> status; // nodeid, value

        public Map<Integer, Float> getStatus() {
            return status;
        }

        public void setStatus(Map<Integer, Float> status) {
            this.status = status;
        }

        public int getTimePoint() {
            return timePoint;
        }

        public void setTimePoint(int timePoint) {
            this.timePoint = timePoint;
        }
    }

    @JSONType(serialzeFeatures=SerializerFeature.BeanToArray, parseFeatures=Feature.SupportArrayToBean)
    public static class EnergyStatus {
        private int nodeId;
        private int time;
        private List<Float> status;//

        public int getNodeId() {
            return nodeId;
        }

        public void setNodeId(int nodeId) {
            this.nodeId = nodeId;
        }

        public List<Float> getStatus() {
            return status;
        }

        public void setStatus(List<Float> status) {
            this.status = status;
        }

        public int getTime() {
            return time;
        }

        public void setTime(int time) {
            this.time = time;
        }

        @Override
        public String toString() {
            return "EnergyStatus{" +
                    "nodeId=" + nodeId +
                    ", time=" + time +
                    ", status=" + status +
                    '}';
        }
    }
}
